package com.llc.spring.cloud.sdk.core.proxy;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * time 2018/8/27 17:56
 *
 * @author xiaojie.zhu <br>
 */
public class TypeUtil {
    private static final List<Class<?>> BASIC_CLASS = Arrays.asList(int.class,Integer.class,short.class,Short.class,long.class,Long.class,String.class, Date.class,float.class,Float.class,double.class,Double.class);

    public static Object getValue(Object obj){
        return obj;
    }

    public static Object getValue(long val){
        return Long.valueOf(val);
    }


    public static Object getValue(int val){
        return Integer.valueOf(val);
    }

    public static Object getValue(short val){
        return Short.valueOf(val);
    }

    public static Object getValue(double val){
        return Double.valueOf(val);
    }

    public static Object getValue(float val){
        return Float.valueOf(val);
    }

    public static boolean isBasicType(Class<?> c){
        return BASIC_CLASS.contains(c);
    }

    public static String getStringReturnType(Class<?> clazz){
        if(clazz == null){
            return "null";
        }else{
            if(BASIC_CLASS.contains(clazz)){
                if(int.class == clazz){
                    return "Integer";
                }else if(short.class == clazz){
                    return "Short";
                }else if(long.class == clazz){
                    return "Long";
                }else if(float.class == clazz){
                    return "Float";
                }else if(double.class == clazz){
                    return "Double";
                }else{
                    return clazz.getName();
                }
            }else{
                return clazz.getName();
            }
        }
    }
}
